/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JP_ListarErrorResultados.java
 *
 * Created on 11/01/2010, 04:39:07 PM
 */

package gui;

import controlacciones.ejb3.pojo.TableBeanBinding_ErrorResultado;
import controlaccionescomercial.ControlAccionesComercialApp;
import delegate.GestionDelegate;
import helper.JP_Utiles_PanelBotonesMantenimiento;
import helper.JP_Utiles_PanelModelo;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Task;

/**
 *
 * @author Vanessa
 */
public class JP_ListarErrorResultados extends JP_Utiles_PanelModelo{

    /** Creates new form JP_ListarErrorResultados */

    public JP_ListarErrorResultados() {
        inicializaComponentes();
        cargaTabla( ControlAccionesComercialApp.LOG_USER );
    }

     private void inicializaComponentes(){
        initComponents();
        //Panel de Operaciones
        ArrayList alBotones = new ArrayList( 1 );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_IMPRIMIR ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_CERRAR ) );
        jp_ope = new JP_Utiles_PanelBotonesMantenimiento( this, alBotones );
        jp_Operaciones.setLayout( new BorderLayout() );
        jp_Operaciones.add( jp_ope, BorderLayout.CENTER );
    }

     private void cargaTabla( String log_user ){

        try {
            listaDatos = GestionDelegate.getInstance().getListaDatosErrorResultado( log_user );
        } catch (Exception ex) {
            System.out.println( "Error al listar Errores de Resultados: " + ex.getMessage() );
        }
        if(listaDatos != null){
            if( listaDatos.isEmpty() ){
               helper.Utiles_MensajesDialogo.mensajeAlerta("No existen Errores de Resultados para mostrar");
            }
        }
        construirTabla();
    }

     private void construirTabla(){
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, listaDatos, this.tbResultadoAcciones);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idError}"));
        columnBinding.setColumnName("Id. Error");
        columnBinding.setColumnClass(Integer.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding2 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idAccion}"));
        columnBinding2.setColumnName("Id. Accion");
        columnBinding2.setColumnClass(Integer.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding3 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numInscri}"));
        columnBinding3.setColumnName("NumInscrip");
        columnBinding3.setColumnClass(String.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding4 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaRegistro}"));
        columnBinding4.setColumnName("Fecha");
        columnBinding4.setColumnClass(String.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding5 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codTipoAccion}"));
        columnBinding5.setColumnName("Tipo Accion");
        columnBinding5.setColumnClass(String.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding6 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${error}"));
        columnBinding6.setColumnName("Error");
        columnBinding6.setColumnClass(String.class);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding7 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${logUser}"));
        columnBinding7.setColumnName("Log User");
        columnBinding7.setColumnClass(String.class);

        bindingGroup.addBinding(jTableBinding);
        bindingGroup.bind();
    }

      public void generarReporte(){
        Map parametros = new HashMap();
        String direcc = "F:/sistemaRRHH/CONTROL DE ACCIONES/";//System.getProperty("user.dir")+"\\";
//         String direcc = "D:\\Proyectos EPS GRAU\\CONTROL DE ACCIONES\\";
        parametros.put("SUBREPORT_DIR",direcc);
        System.err.println("SUBREPORT_DIR  " + direcc );
        try {
            //helper.Utiles_Reporte.generarReporte("Reporte_Resultados_Procesados.jasper", parametros);
            helper.Utiles_Reporte.generarReporte("Reporte_Error_Resultados.jasper", parametros);
        }  catch (Exception ex) {
            //Logger.getLogger(JP_ListarAcciones_Area.class.getName()).log(Level.SEVERE, null, ex);
            System.err.println( "Error al generar el reporte2: " + ex.getMessage() );
        }
    }

    @Override
    public Task imprimir() {
        try {
             generarReporte();             
        } catch (Exception ex) {
            Logger.getLogger(JP_RegistrarResultadoI.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

     @Override
    public Task cerrar() {
        this.cerrarPadre();
        return null;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jp_Operaciones = new javax.swing.JPanel();
        jp_Errores = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbResultadoAcciones = new javax.swing.JTable();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_ListarErrorResultados.class);
        jp_Operaciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_Operaciones.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jp_Operaciones.border.titleColor"))); // NOI18N
        jp_Operaciones.setName("jp_Operaciones"); // NOI18N

        javax.swing.GroupLayout jp_OperacionesLayout = new javax.swing.GroupLayout(jp_Operaciones);
        jp_Operaciones.setLayout(jp_OperacionesLayout);
        jp_OperacionesLayout.setHorizontalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 513, Short.MAX_VALUE)
        );
        jp_OperacionesLayout.setVerticalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 37, Short.MAX_VALUE)
        );

        jp_Errores.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_Errores.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jp_Errores.border.titleFont"))); // NOI18N
        jp_Errores.setName("jp_Errores"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tbResultadoAcciones.setAutoCreateRowSorter(true);
        tbResultadoAcciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbResultadoAcciones.setName("tbResultadoAcciones"); // NOI18N
        jScrollPane1.setViewportView(tbResultadoAcciones);

        javax.swing.GroupLayout jp_ErroresLayout = new javax.swing.GroupLayout(jp_Errores);
        jp_Errores.setLayout(jp_ErroresLayout);
        jp_ErroresLayout.setHorizontalGroup(
            jp_ErroresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
        );
        jp_ErroresLayout.setVerticalGroup(
            jp_ErroresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jp_Operaciones, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jp_Errores, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jp_Errores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jp_Operaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private JP_Utiles_PanelBotonesMantenimiento jp_ope;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jp_Errores;
    private javax.swing.JPanel jp_Operaciones;
    private javax.swing.JTable tbResultadoAcciones;
    // End of variables declaration//GEN-END:variables

    private List<TableBeanBinding_ErrorResultado> listaDatos;
    private org.jdesktop.swingbinding.JTableBinding jTableBinding;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
}
